package com.travel.travelServer.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.travel.travelServer.entity.LoginUser;
import com.travel.travelServer.entity.User;
import com.travel.travelServer.mapper.UserMapper;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Objects;

@Service
public class LoginUserServiceImpl implements UserDetailsService {

    @Resource
    private UserMapper userDao;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        LambdaQueryWrapper<User> userWrapper = new LambdaQueryWrapper<>();
        userWrapper.eq(User::getUsername, username);
        User dbUser = userDao.selectOne(userWrapper);
        if (Objects.isNull(dbUser)){
//            throw new ServiceException("用户名错误!");
        }
        return new LoginUser(dbUser);
    }
}
